package com.lucenly.spell.utils

import android.content.Context
import android.util.DisplayMetrics
import android.view.WindowManager

object DisplayUtil {

    @JvmStatic
    fun getWidth(context: Context): Int {
        val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        var widthPixels = 0
        if (windowManager != null) {
            val outMetrics = DisplayMetrics()
            windowManager.defaultDisplay.getMetrics(outMetrics)
            widthPixels = outMetrics.widthPixels
        }
        return widthPixels
    }

    @JvmStatic
    fun getHeight(context: Context): Int {
        val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        var widthPixels = 0
        if (windowManager != null) {
            val outMetrics = DisplayMetrics()
            windowManager.defaultDisplay.getMetrics(outMetrics)
            widthPixels = outMetrics.heightPixels
        }
        return widthPixels
    }

    @JvmStatic
    fun dip2px(context: Context, dpValue: Float): Int {
        val scale = context.resources.displayMetrics.density
        return (dpValue * scale + 0.5f).toInt()
    }
}